package leetcode;

/**
 * @Description
 * @Author away
 * @Version V1.0.0
 * @Since 1.0
 * @Date 21.6.7
 */

public class T494 {

    public static void main(String[] args) {
        T494 t494 = new T494();
        int[] nums = {1,1,1,1,1};
        int target = 3;
        int targetSumWays = t494.findTargetSumWays(nums, target);
        System.out.println(targetSumWays);
    }

    int result = 0;
    public int findTargetSumWays(int[] nums, int target) {
        findTargetSumWays(nums,nums.length-1,target);
        return result;
    }

    public void findTargetSumWays(int[] nums, int index, int target) {
        System.out.println("index "+ index+" target "+target);
        if (index < 0) {
            return;
        }
        if (index == 0) {
            if (target - nums[index] == 0 ) {
                result++;
            }
            if(target + nums[index] == 0){
                result++;
            }
        } else {
            findTargetSumWays(nums, index - 1, target - nums[index]);
            findTargetSumWays(nums, index - 1, target + nums[index]);
        }
    }
}
